<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input type="text" class="inp" onInput="inps(event)" />
    <h1 class="box"></h1>
    <script>
      let obj = {
        msg: "hello world",
        age: 12,
      };
      let inp = document.querySelector(".inp");
      let box = document.querySelector(".box");
      inp.value = obj.msg;
      box.innerHTML = obj.msg;

      Object.defineProperty(obj, "msg", {
        set(val) {
          console.log(111);
          box.innerHTML = val;
        },
        //   get(){

        //   }
      });
      //对象的defineproperty  方法中含有一个set和get方法，可以设置对象的属性值

      function inps(e) {
        console.log(222);
        obj.msg = e.target.value;
      }
    </script>
  </body>
</html>
